<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${dao_package_name}.${table_name}DAO">
    <resultMap id="BaseResultMap" type="${entity_package_name}.${table_name}">
        <id column="${primaryKey}" jdbcType="INTEGER" property="${primaryKey?uncap_first}"/>
        <#list entity_column as entity>
            <result column="${entity.columnName}" jdbcType="${entity.columnType}"
                    property="${entity.changeColumnName?uncap_first}"/>
        </#list>
    </resultMap>
    <sql id="Base_Column_List">
        <#if entity_column?exists>
            <#list entity_column as entity>
                <#if entity_has_next!=true>
                    ${entity.columnName}
                <#else>
                    ${entity.columnName},
                </#if>
            </#list>
        </#if>
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM ${table_name_small}
        WHERE ${primaryKey} = ${r'#'}{${primaryKey?uncap_first},jdbcType=INTEGER}
    </select>

    <select id="selectByPrimarys" parameterType="${entityPackage}.${table_name}" resultMap="BaseResultMap">
        SELECT
        <#if entity_column?exists>
            <#list entity_column as entity>
                <#if entity_has_next!=true>
                    <if test="${entity.columnName} != null">
                        ${entity.columnName},
                    </if>
                <#else>
                    <if test="${entity.columnName} != null">
                        ${entity.columnName}
                    </if>
                </#if>
            </#list>
        </#if>
        FROM ${table_name_small}
        <where>
            <#if entity_column?exists>
                <#list entity_column as entity>
                    <#if entity_index!=0>
                        <if test="${entity.changeColumnName?uncap_first} !=null">
                            AND ${entity.columnName} = ${r'#'}{${entity.changeColumnName?uncap_first}
                            ,jdbcType=${entity.columnType}}
                        </if>
                    <#else>
                        <if test="${entity.changeColumnName?uncap_first} !=null">
                            AND ${entity.columnName} = ${r'#'}{${entity.changeColumnName?uncap_first}
                            ,jdbcType=${entity.columnType}}
                        </if>
                    </#if>
                </#list>
            </#if>
        </where>
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        DELETE FROM ${table_name_small}
        WHERE ${primaryKey} = ${r'#'}{${primaryKey?uncap_first},jdbcType=INTEGER}
    </delete>

    <insert id="insert" parameterType="${entityPackage}.${table_name}">
        INSERT INTO ${table_name_small} (
        <include refid="Base_Column_List"/>
        )
        values (
        <#if entity_column?exists>
            <#list entity_column as entity>
                <#if entity_has_next!=true>
                    ${r'#'}{${entity.changeColumnName?uncap_first},jdbcType=${entity.columnType}}
                <#else>
                    ${r'#'}{${entity.changeColumnName?uncap_first},jdbcType=${entity.columnType}},
                </#if>
            </#list>
        </#if>
        )
    </insert>

    <insert id="insertSelective" parameterType="${entityPackage}.${table_name}">
        INSERT INTO ${table_name_small}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <#if entity_column?exists>
                <#list entity_column as entity>
                    <if test="${entity.changeColumnName?uncap_first} != null">
                        ${entity.columnName},
                    </if>
                </#list>
            </#if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <#if entity_column?exists>
                <#list entity_column as entity>
                    <if test="${entity.changeColumnName?uncap_first} != null">
                        ${r'#'}{${entity.changeColumnName?uncap_first},jdbcType=${entity.columnType}},
                    </if>
                </#list>
            </#if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="${entityPackage}.${table_name}">
        UPDATE ${table_name_small}
        <set>
            <#if entity_column?exists>
                <#list entity_column as entity>
                    <if test="${entity.changeColumnName?uncap_first} != null">
                        ${entity.columnName} = ${r'#'}{${entity.changeColumnName?uncap_first},jdbcType=${entity.columnType}
                        },
                    </if>
                </#list>
            </#if>
        </set>
        WHERE ${primaryKey} = ${r'#'}{${primaryKey?uncap_first},jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="${entityPackage}.${table_name}">
        UPDATE ${table_name_small}
        SET
        <#if entity_column?exists>
            <#list entity_column as entity>
                <#if entity_has_next!=true>
                    ${entity.columnName} = ${r'#'}{${entity.changeColumnName?uncap_first},jdbcType=${entity.columnType}}
                <#else>
                    ${entity.columnName} = ${r'#'}{${entity.changeColumnName?uncap_first},jdbcType=${entity.columnType}},
                </#if>
            </#list>
        </#if>
        WHERE ${primaryKey} = ${r'#'}{${primaryKey?uncap_first},jdbcType=INTEGER}
    </update>

    <select id="countTotal" parameterType="${entityPackage}.${table_name}">
        SELECT
        COUNT(*)
        FROM ${table_name_small}
        <where>
            <#if entity_column?exists>
                <#list entity_column as entity>
                    <#if entity_index!=0>
                        <if test="${entity.changeColumnName?uncap_first} !=null">
                            AND ${entity.columnName} = ${r'#'}{${entity.changeColumnName?uncap_first}
                            ,jdbcType=${entity.columnType}}
                        </if>
                    <#else>
                        <if test="${entity.changeColumnName?uncap_first} !=null">
                            AND ${entity.columnName} = ${r'#'}{${entity.changeColumnName?uncap_first}
                            ,jdbcType=${entity.columnType}}
                        </if>
                    </#if>
                </#list>
            </#if>
        </where>
    </select>
</mapper>